package gamePackage;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.ArrayList;

import javax.swing.JFrame;
import boardPackage.*; 
import itemPackage.*;
import unitPackage.*;
import casteSubPackage.*;

public class Controller {

	View view;
	
	final static int MENU_HEIGHT = 300;
	final static int MENU_WIDTH = 300;
	final static int GAME_HEIGHT = 800;
	final static int GAME_WIDTH = 800;
	final static int NUM_TILES = 25;
	final static int TILE_SIZE = 32;
	
	static int currentState;
	
	final static int TITLE_STATE = 10000;
	final static int NEW_GAME_STATE = 10001;
	final static int LOAD_GAME_STATE = 10002;
	final static int OPTIONS_STATE = 10003;
	
	Board board;
	
	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args){
		
		Controller controller = new Controller();
		controller.run();

	}

	private void run(){
		
		this.initialize();
		
		System.out.println("Finished initializing. Current State is " + currentState);
		
		
		while(currentState == TITLE_STATE){
			try{
				Thread.sleep(1);
			}catch(InterruptedException e){
				System.out.println(e);
			}
		}
		
		if(currentState == NEW_GAME_STATE){
			//Call new game method here
		}
		else if(currentState == LOAD_GAME_STATE){
			//Call load game method here
		}
		else if(currentState == OPTIONS_STATE){
			//Call options method here
		}
		else{
			//This shouldn't ever happen!
		}
		
		this.tileScreen();
		
		TestFreelancer f = new TestFreelancer();
		f.setMoveDistance(2);
		ArrayList<ArrayList<Integer>> move = f.battleMove();
		System.out.println(move);
		
	}
	
	public static void setCurrentState(int state){
		currentState = state;
		return;
	}
	
	private void initialize(){
		
		view = new View();
		view.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2 - MENU_WIDTH/2, 
				Toolkit.getDefaultToolkit().getScreenSize().height/2 - MENU_WIDTH/2);
		view.setVisible(true);
		view.setTitle("Fibonacci--v0.2");
		view.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		view.setSize(new Dimension(MENU_WIDTH, MENU_HEIGHT));
		view.setResizable(false);
		view.getTitleScreen();
		view.getTileScreen();
		currentState = TITLE_STATE;
		view.setToTitleScreen();
		
	}
	
	private void tileScreen(){

		board = new Board(NUM_TILES*NUM_TILES);
		for(int count = 0; count < board.getTiles().size(); count++){
			board.getTiles().add(new Tile(count%NUM_TILES, count/NUM_TILES));
		}

		view.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2 - GAME_WIDTH/2, 
				Toolkit.getDefaultToolkit().getScreenSize().height/2 - GAME_WIDTH/2);
		view.setSize(new Dimension(GAME_WIDTH + view.getInsets().left + view.getInsets().right, 
				GAME_HEIGHT + view.getInsets().top + view.getInsets().bottom));
		view.setToTileScreen();
		
	}
}
